package m.jclecai.com.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import java.util.List;

import m.jclecai.com.R;
import m.jclecai.com.adapter.base.ViewHolerAdapter;
import m.jclecai.com.adapter.holder.FollowListHolder;
import m.jclecai.com.bean.Response.ResHotPeople;

/**
 * Created by 10538 on 2018/3/5.
 */

public class FollowListAdapter extends ViewHolerAdapter<FollowListHolder> {
    List<ResHotPeople.HotPeopleBean> mData;
    Context mContext;

    public FollowListAdapter(List<ResHotPeople.HotPeopleBean> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }

    @Override
    public FollowListHolder onCreateViewHolder(int position, ViewGroup parent) {
        return new FollowListHolder(mContext, R.layout.item_follow_list);
    }

    @Override
    public void onBindViewHolder(int position, FollowListHolder holder) {
        ResHotPeople.HotPeopleBean hotPeopleBean = mData.get(position);
        Glide.with(mContext).load(hotPeopleBean.getUser_face()).into(holder.ivUserIcon);
        StringBuffer hw = new StringBuffer("0 中 0");
        if (hotPeopleBean != null && !TextUtils.isEmpty(hotPeopleBean.getMilitary_total())) {
            hw.delete(0, hw.length());
            hw.append(" " + hotPeopleBean.getMilitary_total() + " ");
        }
        holder.tvUsername.setText(hotPeopleBean.getUsername());
        holder.tvHistoryWin.setText(Html.fromHtml(hw.toString().replace("/", "中")));
        StringBuffer tm = new StringBuffer();
        tm.append("近7日盈利率：<font color=#d81d36>" + hotPeopleBean.getPayback_total() + "</font>");
        holder.tvTotalMoney.setText(Html.fromHtml(tm.toString()));
        holder.tvFans.setText("粉丝数:" + hotPeopleBean.getFans());
        holder.tvFollowCount.setText(hotPeopleBean.getUser_project_follow());
        holder.tvFollowCount.setVisibility(View.GONE);
        holder.tvFollow.setVisibility(View.GONE);
        if (hotPeopleBean != null && !TextUtils.isEmpty(hotPeopleBean.getUser_project_follow())
                && !"0".equals(hotPeopleBean.getUser_project_follow())) {
            holder.tvFollowCount.setVisibility(View.VISIBLE);
            holder.tvFollow.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getCount() {
        return mData.size();
    }
}
